<template>
	<view class="content">
		分包页面2
		<text @click="goTopage">这个是分包页面2</text>
		<div>测试获取vuex--globalInfo:{{globalInfo}}</div>
		<div>测试获取vuex--token:{{token}}</div>

		<div>分包图片测试2</div>
		<image src="/subPackages/page1/static/images/fail.png" mode=""></image>
		
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				title: 'subpackages2',
				scriptsLoaded: false,
			};
		},
		onLoad() {
			console.log(this.$store.state, '获取vuex信息数据')
			console.log(this.$Route.query, '获取的传递参数', this.$Route.params)
		},
		computed: {
			// 方式1：通过 mapState 映射（需指定模块名）
			...mapState('user', {
				token: state => state.token
			}),
			// 方式2：通过 mapGetters 映射
			...mapGetters('user', ['globalInfo'])
		},
		methods: {

			goTopage() {
				console.log('111')
			},

			// 加载腾讯地图qq.map需要异步引入
			loadScript(src, type) {
				const script = document.createElement('script');
				script.src = src;
				script.async = true;
				script.type = 'text/javascript';

				script.onload = () => {
					console.log(`${type}脚本加载成功`);
					this.scriptsLoaded[type] = true;
					this.checkAllScriptsLoaded();
				};

				script.onerror = () => {
					console.error(`${type}脚本加载失败`);
					uni.showToast({
						title: `${type}加载失败`,
						icon: 'none'
					});
				};

				document.head.appendChild(script);
			},
			// 检查所有脚本是否加载完成
			checkAllScriptsLoaded() {
				const {
					tencentMap,
					geolocation
				} = this.scriptsLoaded;
				if (tencentMap && geolocation) {
					console.log('所有脚本加载完成，初始化地图和定位');
				}
			},
		}
	};
</script>

<style>
	.content {
		text-align: center;
		height: 400upx;
		margin-top: 200upx;
	}
</style>